package de.tum.in.eist.poll.shared.dao;

import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import de.tum.in.eist.poll.shared.beans.Feedback;
import de.tum.in.eist.poll.shared.beans.StudentLectureKey;

/**
 * This is an in-memory implementation of the {@link FeedbackDaoInterface}.
 * 
 * @author The EIST-POLL-21 team.
 *
 */
public class FeedbackDaoImpl implements FeedbackDaoInterface {
	/**
	 * 
	 */
	TreeMap<StudentLectureKey,Feedback> feedbackMap;

	@Override
	public void add(Feedback feedback) {
		feedbackMap.put(new StudentLectureKey(feedback.getLectureID(),
				feedback.getStudentID()), feedback);
	}

	@Override
	public Feedback get(String lectureID, String studentID) {
		return feedbackMap.get(new StudentLectureKey(lectureID, studentID));
	}

	@Override
	public Set<Feedback> getByStudent(String studentID) {
		// TODO: this is kinda inefficient...
		Set<Feedback> result = new TreeSet<Feedback>();
		Set<StudentLectureKey> keySet = feedbackMap.keySet();
		for (StudentLectureKey key : keySet) {
			if (key.getStudentID() == studentID)
				result.add(feedbackMap.get(key));
		}
		return result;
	}

	@Override
	public Set<Feedback> getByLecture(String lectureID) {
		// TODO: this is kinda inefficient...
		Set<Feedback> result = new TreeSet<Feedback>();
		Set<StudentLectureKey> keySet = feedbackMap.keySet();
		for (StudentLectureKey key : keySet) {
			if (key.getLectureID() == lectureID)
				result.add(feedbackMap.get(key));
		}
		return result;
	}
}

